package cn.yunhe.actions.temp;

import cn.yunhe.model.House;
import cn.yunhe.service.HouseBiz;
import cn.yunhe.util.BaseActionUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/*spring注解*/
@Controller(value = "houseAction1")
@Scope(value = "prototype")
/*struts2注解*/
@ParentPackage(value = "struts-default")
public class HouseAction1 extends BaseActionUtil {

    /*spring注解*/
    @Autowired
    @Qualifier("houseBiz")
    HouseBiz houseBiz;

    /*struts2注解*/
    @Action(value = "house_searchHouse1",results = {
            @Result(name = "success",location = "/searcHouse.jsp"),
            @Result(name = "error",location = "/fail2SearcHouse.jsp"),
    })
    public String searchHouse(){
        //此处的House1对应
        //@Entity(name = "House1")
        //@Table(name = "house")
        List<House>houseList=houseBiz.searchHouse("from House1");
        getRequest().setAttribute("houseList1",houseList);
        list(houseList);
        return SUCCESS;
    }

    public HouseBiz getHouseBiz() {
        return houseBiz;
    }

    public void setHouseBiz(HouseBiz houseBiz) {
        this.houseBiz = houseBiz;
    }

    public void list(List<House> houseList){
        for (House house:houseList){
            singleHouse(house);
        }
    }

    public void singleHouse(House house){
        System.out.print(house.getHid()+"\t");
        System.out.print(house.getHtitle()+"\t");
        System.out.print(house.getHprice()+"\t");
        System.out.print(house.getHfloorage()+"\t");
        System.out.print(house.getHpubdate()+"\t");
        System.out.print(house.getHcontact()+"\t");
        System.out.print(house.getHdesc()+"\t");
        System.out.print(house.getHflag()+"\t");
        if (house.getMember().getMname()!=null)
            System.out.print(house.getMember().getMname()+house.getMember().getMid()+"\t");
        if (house.getType().getTname()!=null)
            System.out.print(house.getType().getTname()+house.getType().getTid()+"\t");
        if (house.getStreet().getSname()!=null)
            System.out.print(house.getStreet().getSname()+house.getStreet().getSid()+"\t");
        if (house.getStreet().getDistrict().getDname()!=null)
            System.out.print(house.getStreet().getDistrict().getDname()+house.getStreet().getDistrict().getDid()+"\t");
        System.out.println();
    }
}
